home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…eptember: Technology Seed / September 98 ADC Seed CD.toast / Language Analysis Manager / DarumaDR1Package / Examples / DictionaryAccess / Sources / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.9 KB  |  185 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Events.c
  3.     
  4.     Contains:    A Sample application for dictionary access.
  5.  
  6.      Version:    Technology:    System 8
  7.                  Release:    Daruma Developer Release 1
  8.  
  9.      Copyright:    1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Contact:    daruma@apple.com
  12.  
  13. */
  14.  
  15.  
  16. #include "DictionaryAccess.h"
  17. #include "FunctionProto.h"
  18.  
  19. #include <Menus.h>
  20. #include <Devices.h>
  21. #include <TextUtils.h>
  22. #include <Resources.h>
  23. #include <Appearance.h>
  24. #include <TextServices.h>
  25.  
  26. // ========================================================================================
  27. // Global variables
  28. // ========================================================================================
  29. static Boolean        gQuitNow;
  30.  
  31. // ========================================================================================
  32. // Prototypes for static functions
  33. // ========================================================================================
  34. static void HandleMenus ( long menuResult );
  35. static void AdjustMenus ( void );
  36.  
  37. // ========================================================================================
  38. // MainEventLoop
  39. // ========================================================================================
  40. void MainEventLoop ( void )
  41. {
  42.     EventRecord        theEvent;
  43.     Boolean            gotEvent;
  44.     WindowPtr        whichWindow;
  45.     SInt16            partCode;
  46.     
  47.     gQuitNow = false;
  48.     
  49.     while ( true)
  50.     {
  51.         gotEvent = WaitNextEvent( everyEvent, &theEvent, 0L, nil);
  52.         
  53.         if ( gotEvent)
  54.         {
  55.             switch ( theEvent.what)
  56.             {
  57.             case mouseDown:
  58.                 partCode = FindWindow( theEvent.where, &whichWindow);
  59.                 
  60.                 switch ( partCode )
  61.                 {
  62.                 case inMenuBar:
  63.                     AdjustMenus();
  64.                     HandleMenus( MenuSelect( theEvent.where));
  65.                     break;
  66.                 default:
  67.                     break;
  68.                 }
  69.                 break;
  70.             
  71.             case keyDown:
  72.                 if ( theEvent.modifiers & cmdKey )
  73.                 {
  74.                     AdjustMenus();
  75.                     HandleMenus( MenuKey( theEvent.message & charCodeMask));
  76.                 }
  77.                 break;
  78.                 
  79.             case kHighLevelEvent:
  80.                 AEProcessAppleEvent( &theEvent);
  81.                 break;
  82.  
  83.             case updateEvt:
  84.             case activateEvt:
  85.             case nullEvent:
  86.                 break;
  87.             
  88.             default:
  89.                 break;
  90.             }
  91.         }
  92.         
  93.         if ( gQuitNow)
  94.             break;
  95.     }
  96. }
  97.  
  98.  
  99. // ========================================================================================
  100. // HandleMenus
  101. // ========================================================================================
  102. static void HandleMenus ( long menuResult )
  103. {
  104.     short                menuID, menuItem;
  105.     Str255                itemName;
  106.     
  107.     if ( menuResult == 0) return;
  108.     
  109.     menuID = ( ( menuResult >> 16) & 0x0000FFFF);
  110.     menuItem = ( menuResult & 0x0000FFFF);
  111.     
  112.     switch ( menuID)
  113.     {
  114.     case kAppleMenuID:
  115.         switch ( menuItem)
  116.         {
  117.         case kAboutMenuItemID:
  118.             break;
  119.         default:
  120.             GetMenuItemText( GetMenuHandle( menuID), menuItem, itemName);
  121.             OpenDeskAcc( itemName);
  122.             break;
  123.         }
  124.         break;
  125.         
  126.     case kFileMenuID:
  127.         switch ( menuItem)
  128.         {
  129.         case kOpenMenuItemID:
  130.             DoOpenDictionaryFile();
  131.             break;
  132.         case kQuitMenuItemID:
  133.             gQuitNow = true;
  134.             break;
  135.         default:
  136.             break;
  137.         }
  138.         break;
  139.     
  140.     case kEditMenuID:
  141.         break;
  142.                 
  143.     default:
  144.         break;
  145.     }
  146.     
  147.     HiliteMenu( 0);
  148. }
  149.  
  150.  
  151. // ========================================================================================
  152. // AdjustMenus
  153. // ========================================================================================
  154. static void AdjustMenus ( void )
  155. {
  156.     // Do nothing for now
  157. }
  158.  
  159.  
  160. // ========================================================================================
  161. // DoQuit
  162. // ========================================================================================
  163. static void DoQuit( void )
  164. {
  165.     gQuitNow = true;
  166.     CloseTSMAwareApplication();
  167.     UnregisterAppearanceClient();
  168. }
  169.  
  170.  
  171. //========================================================================================
  172. //        AEQuitHandler
  173. //========================================================================================
  174. pascal OSErr AEQuitHandler( AppleEvent *messagein, AppleEvent *reply, long handlerRefcon)
  175. {
  176. #pragma unused (messagein, reply, handlerRefcon)
  177.     
  178.     gQuitNow = true;
  179.     
  180.     return noErr;
  181. }
  182.  
  183.  
  184.  
  185.